package com.bcxj.apipassenger.controller;

import com.bcxj.apipassenger.interceptor.JwtInterceptor;
import com.bcxj.apipassenger.service.UserService;
import com.bcxj.internalcommon.response.ResponseResult;
import com.bcxj.internalcommon.response.TokenResult;
import com.bcxj.internalcommon.util.JwtUtils;
import com.bcxj.internalcommon.vo.TravelUserVO;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * ClassName: UserController
 * Package: com.bcxj.apipassenger.controller
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/3/5 23:46
 * @Version 1.0
 * @Since 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 获取用户的信息
     * @param request
     * @return
     */
    @GetMapping("get")
    public ResponseResult<TravelUserVO> get(HttpServletRequest request) {
        TokenResult tokenRes = JwtUtils.parseToken(request.getHeader("Authorization"));
        return userService.getUser(tokenRes.getPhone());
    }


    /**
     * 用户退出登录
     * @param phone
     * @return
     */
    @PostMapping("/out")
    public ResponseResult out(String phone) {
        return userService.out(phone);
    }


}
